//package com.punch.order.service.impl;
//
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.lang.Snowflake;
//import cn.hutool.core.util.IdUtil;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.punch.common.dto.course.ClassStartDTO;
//import com.punch.common.dto.order.OrderCancelDTO;
//import com.punch.common.dto.order.OrderDTO;
//import com.punch.common.dto.order.SimpleOrderDTO;
//import com.punch.common.enums.course.ClassAuditEnum;
//import com.punch.common.enums.course.GradeEnum;
//import com.punch.common.enums.order.OrderStatusEnum;
//import com.punch.common.exception.BusinessException;
//import com.punch.common.feign.FeignClassService;
//import com.punch.common.feign.FeignStudentService;
//import com.punch.common.page.PageInfo;
//import com.punch.common.query.order.OrderQueryInfo;
//import com.punch.common.redis.lock.RedissonDistributedLock;
//import com.punch.common.redis.utils.UserUtil;
//import com.punch.common.tools.BasePage;
//import com.punch.common.utils.BigDecimalUtil;
//import com.punch.common.utils.IdGenerator;
//import com.punch.common.vo.course.AppClassVO;
//import com.punch.common.vo.order.*;
//import com.punch.common.vo.pay.WXPayVO;
//import com.punch.common.vo.user.student.StudentVO;
//import com.punch.order.asyn.OrderAsync;
//import com.punch.order.exception.OrderExceptionEnum;
//import com.punch.order.mapper.OrderMapper;
//import com.punch.order.model.OrderCourseSnapshot;
//import com.punch.order.model.MaterialOrder;
//import com.punch.order.model.Order;
//import com.punch.order.service.*;
//import com.punch.order.util.ArrayUtil;
//import com.punch.order.wxpay.constant.WXPayConstants;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import java.math.BigDecimal;
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.time.LocalTime;
//import java.time.Period;
//import java.util.*;
//
//
///**
// * OrderServiceImpl-订单实现层
// *
// * @author wujj
// * @version 1.0.0
// * @since 2020/7/14 11:27
// */
//@Service
//@Slf4j
//public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
//
//    @Resource
//    private FeignClassService feignClassService;
//
//    @Resource
//    private FeignStudentService feignStudentService;
//
//    @Resource
//    private CourseOrderService courseOrderService;
//
//    @Resource
//    private MaterialOrderService materialOrderService;
//
//    @Resource
//    private OrderAsync orderAsync;
//
//    @Resource
//    private PayService payService;
//
//    @Resource
//    private RedissonDistributedLock redissonDistributedLock;
//
//    @Resource
//    private RefundService refundService;
//
////    /**
////     * 下单前进行验证
////     *
////     * @param courseClassId 课程id
////     * @param studentId     学生id
////     * @param studentName   学生姓名
////     * @param coursePrice   课程价格
////     * @return 是否有资格报名
////     */
////    @Override
////    public Boolean validateOrder(Long courseClassId, Long studentId, String studentName, BigDecimal coursePrice) {
////        //同一个学生在同一个班级只能报一次
////        sameClassSignUpValidate(courseClassId, studentId, studentName);
////        //同一天（同一时间段）只能报一门课程
////        sameTimeOnlyOneClassValidate(studentId, studentName);
////        //费用不超过150的限制，平均每月，每个学期按4个月算
////        registrationFeeValidate(studentId, coursePrice, studentName);
////        return true;
////    }
//
//
//    /**
//     * 创建订单
//     *
//     * @param orderDTO 订单表单
//     * @return 订单id
//     */
//    @Override
//    @Transactional(rollbackFor = RuntimeException.class)
//    public WXPayVO createOrder(OrderDTO orderDTO, HttpServletRequest request) {
//        log.info("用户创建订单数据:{}", orderDTO);
//        StudentVO studentVO = feignStudentService.getFeignStudentById(orderDTO.getStudentId());
//        if (studentVO == null || studentVO.getStudentId() == null) {
//            throw new BusinessException(OrderExceptionEnum.FEIGN_ERROR.getCode(), "远程调用用户服务失败");
//        }
//        AppClassVO appClassVO = redissonLock(orderDTO.getCourseClassId());
//        //同一个学生在同一个班级只能报一次
//        sameClassSignUpValidate(orderDTO.getCourseClassId(), orderDTO.getStudentId(), orderDTO.getStudentName());
//        //同一天（同一时间段）只能报一门课程
//        sameTimeOnlyOneClassValidate(orderDTO.getStudentId(), orderDTO.getStudentName(), appClassVO.getCourseName(), appClassVO.getCourseWeek(), appClassVO.getClassTime());
//        //费用不超过150的限制，平均每月，每个学期按4个月算
//        registrationFeeValidate(orderDTO.getStudentId(), orderDTO.getCoursePrice(), orderDTO.getStudentName());
//        //报名只能报对应适用年级的课程
//        courseGradeValidate(String.valueOf(studentVO.getGradeYear()), appClassVO.getCourseGrade(), appClassVO.getCourseGradeName());
//        checkMoney(appClassVO, orderDTO);
//        String orderNo = generateOrderNo();
//        Order order = new Order();
//        //主订单信息
//        fillMainOrder(orderDTO, order, orderNo);
//        Integer materialMoneyFee = BigDecimalUtil.getMoneyFee(orderDTO.getMaterialPrice() == null ? new BigDecimal(0) : orderDTO.getMaterialPrice());
//        order.setMaterialOrderFee(materialMoneyFee);
//        if (!save(order)) {
//            log.error("创建订单有误:{}", order);
//            throw new BusinessException(OrderExceptionEnum.CREATE_ORDER_ERROR);
//        }
//        //插入课程订单表
//        OrderCourseSnapshot orderCourseSnapshot = new OrderCourseSnapshot();
//        orderCourseSnapshot.setOrderNo(orderNo);
//        orderCourseSnapshot.setCourseCreateId(appClassVO.getCourseCreateId());
//        orderCourseSnapshot.setMainOrderId(order.getId());
//        fillCourseOrder(appClassVO, studentVO, orderCourseSnapshot);
//        orderCourseSnapshot.setOrderStatus(order.getOrderStatus());
//        courseOrderService.save(orderCourseSnapshot);
//        //包含教具
//        Long materialOrderId = 0L;
//        if (orderDTO.getContainMaterialFlag() == 1) {
//            //插入材料订单表
//            MaterialOrder materialOrder = new MaterialOrder();
//            materialOrder.setOrderNo(orderNo);
//            materialOrder.setMaterialOrderFee(materialMoneyFee);
//            materialOrder.setSupplierId(appClassVO.getSupplierId());
//            materialOrder.setSupplierName(appClassVO.getSupplierName());
//            materialOrder.setMainOrderId(order.getId());
//            materialOrder.setCourseId(appClassVO.getCourseId());
//            materialOrder.setCourseClassId(appClassVO.getClassId());
//            materialOrder.setOrderStatus(order.getOrderStatus());
//            materialOrderService.save(materialOrder);
//            materialOrderId = materialOrder.getId();
//        }
//        WXPayVO wxPayVO;
//        String wxReturn = "";
//        if (order.getTotalFee() > 0) {
//            //需要把统一下单成功的prepay_id传给前端,从支付服务中获取
//            wxPayVO = payService.unifiedorder(orderNo, order.getTotalFee(), appClassVO.getClassId(), UserUtil.getLoginUser().getOpenId(), request);
//            if (wxPayVO == null) {
//                throw new BusinessException(OrderExceptionEnum.UNIFIEDORDER_PAY_ERROR);
//            }
//            wxReturn = wxPayVO.getWxReturn();
//        } else {
//            wxPayVO = new WXPayVO();
//            //2.修改punch_class报名人数,需要分布式事务 Seata
//            Boolean flag = feignClassService.updateSignUpNumber(order.getCourseClassId());
//            if (!flag) {
//                throw new BusinessException(OrderExceptionEnum.UPDATE_SIGN_UP_NUMBER_ERROR);
//            }
//        }
//        //插入日志表-异步
//        orderAsync.insertToOrderRecord(order.getId(), orderCourseSnapshot.getId(), materialOrderId, WXPayConstants.UNIFIEDORDER_OPT_REMARK, wxReturn);
//        return wxPayVO;
//    }
//
//
//    /**
//     * 查询家长下的订单信息列表
//     *
//     * @param orderQueryInfo 查询条件
//     * @return PageInfo<OrderAppPageVO>
//     * @author xiaol
//     * @since 2020/7/23
//     */
//    @Override
//    public PageInfo<OrderAppPageVO> listAppOrder(OrderQueryInfo orderQueryInfo) {
//        orderQueryInfo.setCreateId(UserUtil.getLoginUser().getUserId());
//        return BasePage.queryBasePage(orderQueryInfo, params -> this.getBaseMapper().queryCount(params),
//                params -> {
//                    List<OrderAppPageVO> retList = this.getBaseMapper().queryAppList(params);
//                    retList.forEach(this::accept);
//                    return retList;
//                });
//    }
//
//    /**
//     * 获取订单详情
//     *
//     * @param orderId 订单id
//     * @return OrderAppDetailVO
//     */
//    @Override
//    public OrderAppDetailVO getAppOrder(Long orderId) {
//        Order orderEX = getById(orderId);
//        if (orderEX == null) {
//            throw new BusinessException(OrderExceptionEnum.ORDER_NOT_EXIST);
//        }
//        OrderAppDetailVO orderAppDetailVO = new OrderAppDetailVO();
//        orderAppDetailVO.setOrderId(orderId);
//        orderAppDetailVO.setOrderNo(orderEX.getOrderNo());
//        orderAppDetailVO.setCreateTime(orderEX.getCreateTime());
//        orderAppDetailVO.setCourseOrderPrice(BigDecimalUtil.getMoneyBigDecimal(orderEX.getCourseOrderFee()));
//        orderAppDetailVO.setTotalPrice(BigDecimalUtil.getMoneyBigDecimal(orderEX.getTotalFee()));
//        orderAppDetailVO.setContainMaterialFlag(orderEX.getContainMaterialFlag());
//        //是否包含教具
//        if (orderEX.getContainMaterialFlag() == 1) {
//            orderAppDetailVO.setMaterialOrderPrice(BigDecimalUtil.getMoneyBigDecimal(orderEX.getMaterialOrderFee()));
//        }
//        //查找课程订单
//        QueryWrapper<OrderCourseSnapshot> courseOrderQueryWrapper = new QueryWrapper<>();
//        courseOrderQueryWrapper.lambda().eq(OrderCourseSnapshot::getMainOrderId, orderId);
//        OrderCourseSnapshot orderCourseSnapshotEX = courseOrderService.getOne(courseOrderQueryWrapper);
//        BeanUtils.copyProperties(orderCourseSnapshotEX, orderAppDetailVO);
//        orderAppDetailVO.setOrderStatus(orderEX.getOrderStatus());
//        orderAppDetailVO.setOrderStatusName(OrderStatusEnum.getName(orderEX.getOrderStatus()));
//        orderAppDetailVO.setCourseHourPrice(BigDecimalUtil.getMoneyBigDecimal(orderCourseSnapshotEX.getCourseHourFee()));
//        orderAppDetailVO.setClassName(orderCourseSnapshotEX.getCourseClassName());
//        return orderAppDetailVO;
//    }
//
//    /**
//     * 订单列表
//     *
//     * @param orderQueryInfo 查询条件
//     * @return OrderPageVO订单信息
//     * @author wujj
//     * @since 2020/9/17 13:16
//     */
//    @Override
//    public PageInfo<OrderPageVO> listOrder(OrderQueryInfo orderQueryInfo) {
//        return BasePage.queryBasePage(orderQueryInfo, params -> this.getBaseMapper().queryCount(params),
//                params -> this.getBaseMapper().queryList(params));
//    }
//
//    /**
//     * 订单详情
//     *
//     * @param orderId 订单id
//     * @return OrderDetailVO
//     * @author wujj
//     * @since 2020/9/17 16:25
//     */
//    @Override
//    public OrderDetailVO getOrder(Long orderId) {
//        Order orderEX = getById(orderId);
//        if (orderEX == null) {
//            throw new BusinessException(OrderExceptionEnum.ORDER_NOT_EXIST);
//        }
//        OrderDetailVO orderDetailVO = new OrderDetailVO();
//        orderDetailVO.setOrderNo(orderEX.getOrderNo());
//        orderDetailVO.setCreateTime(orderEX.getCreateTime());
//        orderDetailVO.setOrderStatus(orderEX.getOrderStatus());
//        orderDetailVO.setOrderId(orderId);
//        orderDetailVO.setPayChannel(orderEX.getPayChannel());
//        orderDetailVO.setWxTransactionId(orderEX.getWxTransactionId());
//        orderDetailVO.setTotalPrice(BigDecimalUtil.getMoneyBigDecimal(orderEX.getTotalFee()));
//        //查找课程订单
//        QueryWrapper<OrderCourseSnapshot> courseOrderQueryWrapper = new QueryWrapper<>();
//        courseOrderQueryWrapper.lambda().eq(OrderCourseSnapshot::getMainOrderId, orderId);
//        OrderCourseSnapshot orderCourseSnapshotEX = courseOrderService.getOne(courseOrderQueryWrapper);
//        orderDetailVO.setStudentName(orderCourseSnapshotEX.getStudentName());
//        orderDetailVO.setStudentClass(orderCourseSnapshotEX.getStudentClass());
//        orderDetailVO.setSchoolName(orderCourseSnapshotEX.getSchoolName());
//        if (orderCourseSnapshotEX.getCourseCreateType() == 0) {
//            orderDetailVO.setOrgName(orderCourseSnapshotEX.getCourseCreateName());
//        }
//
//        return orderDetailVO;
//    }
//
//    /**
//     * 获取用户订单状态统计
//     *
//     * @return map
//     */
//    @Override
//    public Map<String, Integer> getOrderStatusCount() {
//        Long userId = UserUtil.getLoginUserId();
//        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(Order::getOrderStatus, OrderStatusEnum.TO_PAY.getCode())
//                .eq(Order::getCreateId, userId);
//        int toPayCount = count(queryWrapper);
//        Map<String, Integer> map = new HashMap<>();
//        map.put("toPayCount", toPayCount);
//        queryWrapper.clear();
//        queryWrapper.lambda().eq(Order::getOrderStatus, OrderStatusEnum.TO_OPEN_CLASS.getCode())
//                .eq(Order::getCreateId, userId);
//        int toBeginClassCount = count(queryWrapper);
//        map.put("toBeginClassCount", toBeginClassCount);
//        return map;
//    }
//
//    /**
//     * 支付回调成功，完成订单状态
//     *
//     * @param wxTransactionId 微信支付交易号
//     * @param orderNo         订单号
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void finishOrder(String wxTransactionId, String orderNo, String callBackStr) {
//        //1.修改订单(主订单、课程订单、教具订单)状态  OrderStatusEnum.TO_OPEN_CLASS
//        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(Order::getOrderNo, orderNo);
//        Order orderEX = getOne(queryWrapper);
//        if (orderEX == null) {
//            log.error("订单号:{}订单不存在", orderNo);
//            throw new BusinessException(OrderExceptionEnum.ORDER_NOT_EXIST);
//        }
//        if (orderEX.getOrderStatus() != OrderStatusEnum.TO_PAY.getCode()) {
//            log.info("订单已经处理:{}--状态:{}", orderNo, orderEX.getOrderStatus());
//            return;
//        }
//        Order order = new Order();
//        order.setId(orderEX.getId());
//        order.setOrderNo(orderEX.getOrderNo());
//        order.setContainMaterialFlag(orderEX.getContainMaterialFlag());
//        order.setOrderStatus(OrderStatusEnum.TO_OPEN_CLASS.getCode());
//        order.setWxTransactionId(wxTransactionId);
//        String optRemark = WXPayConstants.PAY_FINISH_OPT_REMARK;
//        order.setPayTime(LocalDateTime.now());
//        updateOrderStatus(order, optRemark, callBackStr);
//        //2.修改punch_class报名人数,需要分布式事务 Seata
//        Boolean flag = feignClassService.updateSignUpNumber(orderEX.getCourseClassId());
//        if (!flag) {
//            throw new BusinessException(OrderExceptionEnum.UPDATE_SIGN_UP_NUMBER_ERROR);
//        }
//    }
//
//    /**
//     * 开班修改订单状态
//     *
//     * @param classStartDTO 开课信息
//     * @return 是否成功
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public boolean startClass(ClassStartDTO classStartDTO) {
//        //该班级下所有订单都都需要变成待开班
//        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(Order::getCourseClassId, classStartDTO.getClassId())
//                .eq(Order::getOrderStatus, OrderStatusEnum.TO_OPEN_CLASS.getCode());
//        List<Order> list = list(queryWrapper);
//        list.forEach(orderEX -> {
//            Order order = new Order();
//            order.setId(orderEX.getId());
//            order.setOrderNo(orderEX.getOrderNo());
//            order.setContainMaterialFlag(orderEX.getContainMaterialFlag());
//            order.setOrderStatus(OrderStatusEnum.HAVE_OPEN_CLASS.getCode());
//            updateOrderStatus(order, WXPayConstants.STARTCLASSORDER_OPT_REMARK, "");
//        });
//        //异步任务结算课程班级的教具
//        if (classStartDTO.getContainMaterialFlag() == 1) {
//            //插入教具订单供应商信息
//            materialOrderService.updateMaterialOrderSupplier(classStartDTO);
//            orderAsync.insertMaterialSettlement(classStartDTO.getClassId());
//        }
//        return true;
//    }
//
//    /**
//     * 修改订单状态
//     *
//     * @param order     订单信息
//     * @param optRemark 备注信息
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void updateOrderStatus(Order order, String optRemark, String infoRemarks) {
//        //主订单修改成待开班
////        Order order = new Order();
////        order.setId(orderId);
////        order.setOrderStatus(orderStatus);
////        if (orderStatus == OrderStatusEnum.TO_OPEN_CLASS.getCode()) {
////            order.setPayTime(LocalDateTime.now());
////        }
//        String orderNo = order.getOrderNo();
//        Integer orderStatus = order.getOrderStatus();
//        Long orderId = order.getId();
//        Integer containMaterialFlag = order.getContainMaterialFlag();
//        updateById(order);
//        //课程订单修改状态
//        QueryWrapper<OrderCourseSnapshot> courseOrderQueryWrapper = new QueryWrapper<>();
//        courseOrderQueryWrapper.lambda().eq(OrderCourseSnapshot::getOrderNo, orderNo);
//        courseOrderQueryWrapper.lambda().eq(OrderCourseSnapshot::getOrderNo, orderNo);
//        OrderCourseSnapshot orderCourseSnapshotEX = courseOrderService.getOne(courseOrderQueryWrapper);
//        if (orderCourseSnapshotEX == null) {
//            log.error("课程订单号:{}订单不存在", orderNo);
//            throw new BusinessException(OrderExceptionEnum.ORDER_NOT_EXIST);
//        }
//        OrderCourseSnapshot orderCourseSnapshot = new OrderCourseSnapshot();
//        orderCourseSnapshot.setOrderStatus(orderStatus);
//        orderCourseSnapshot.setId(orderCourseSnapshotEX.getId());
//        courseOrderService.updateById(orderCourseSnapshot);
//        //如果有教具订单,修改教具订单状态
//        long materialOrderId = 0;
//        if (containMaterialFlag == 1) {
//            QueryWrapper<MaterialOrder> materialOrderQueryWrapper = new QueryWrapper<>();
//            materialOrderQueryWrapper.lambda().eq(MaterialOrder::getOrderNo, orderNo);
//            MaterialOrder materialOrderEX = materialOrderService.getOne(materialOrderQueryWrapper);
//            if (materialOrderEX == null) {
//                log.error("教具订单号:{}订单不存在", orderNo);
//                throw new BusinessException(OrderExceptionEnum.ORDER_NOT_EXIST);
//            }
//            MaterialOrder materialOrder = new MaterialOrder();
//            materialOrder.setOrderStatus(orderStatus);
//            materialOrder.setId(materialOrderEX.getId());
//            materialOrderService.updateById(materialOrder);
//            materialOrderId = materialOrderEX.getId();
//        }
//        //异步插入流水记录
//        orderAsync.insertToOrderRecord(orderId, orderCourseSnapshotEX.getId(), materialOrderId, optRemark, infoRemarks);
//    }
//
//    /**
//     * 待支付订单进行支付
//     *
//     * @param orderId 订单id
//     * @return 支付回调信息
//     */
//    @Override
//    public WXPayVO payOrder(Long orderId, HttpServletRequest request) {
//        //检查库存够不够
//        Order orderEX = getById(orderId);
//        if (orderEX == null) {
//            throw new BusinessException(OrderExceptionEnum.ORDER_NOT_EXIST);
//        }
//        if (orderEX.getOrderStatus() != OrderStatusEnum.TO_PAY.getCode()) {
//            throw new BusinessException(OrderExceptionEnum.ORDER_STATUS_ERROR);
//        }
//        //金额为负数验证
//        if (orderEX.getTotalFee() < 0
//                || orderEX.getCourseOrderFee() < 0
//                || orderEX.getMaterialOrderFee() < 0) {
//            log.error("订单:{}金额为负数", orderId);
//            throw new BusinessException(OrderExceptionEnum.COURSE_AMOUNT_ERROR);
//        }
//        //不含教具
//        if (orderEX.getContainMaterialFlag() == 0) {
//            if (!orderEX.getTotalFee().equals(orderEX.getCourseOrderFee())) {
//                log.error("不含教具===订单:{},金额不相等。总金额:{},课程金额:{}", orderId, orderEX.getTotalFee(), orderEX.getCourseOrderFee());
//                throw new BusinessException(OrderExceptionEnum.COURSE_AMOUNT_ERROR);
//            }
//        }
//        //包含教具
//        if (orderEX.getContainMaterialFlag() == 1) {
//            Integer total = orderEX.getCourseOrderFee() + orderEX.getMaterialOrderFee();
//            if (!orderEX.getTotalFee().equals(total)) {
//                log.error("含教具===订单:{},金额不相等。总金额:{},课程金额:{},教具金额:{}", orderId, orderEX.getTotalFee(), orderEX.getCourseOrderFee(), orderEX.getMaterialOrderFee());
//                throw new BusinessException(OrderExceptionEnum.COURSE_AMOUNT_ERROR);
//            }
//        }
//
//        OrderCourseSnapshot orderCourseSnapshotEX = getCourseOrder(orderEX.getOrderNo());
//        redissonLock(orderEX.getCourseClassId());
//        //同一天（同一时间段）只能报一门课程
//        sameTimeOnlyOneClassValidate(orderCourseSnapshotEX.getStudentId(), orderCourseSnapshotEX.getStudentName(), orderCourseSnapshotEX.getCourseName(), orderCourseSnapshotEX.getCourseWeek(), orderCourseSnapshotEX.getClassTime());
//        //费用不超过150的限制，平均每月，每个学期按4个月算
//        BigDecimal coursePrice = BigDecimalUtil.getMoneyBigDecimal(orderCourseSnapshotEX.getCourseTotalFee());
//        registrationFeeValidate(orderCourseSnapshotEX.getStudentId(), coursePrice, orderCourseSnapshotEX.getStudentName());
//        //需要把统一下单成功的prepay_id传给前端,从支付服务中获取
//        WXPayVO wxPayVO = payService.unifiedorder(orderEX.getOrderNo(), orderEX.getTotalFee(), orderEX.getCourseClassId(), UserUtil.getLoginUser().getOpenId(), request);
//        if (wxPayVO == null) {
//            throw new BusinessException(OrderExceptionEnum.UNIFIEDORDER_PAY_ERROR);
//        }
//
//        QueryWrapper<MaterialOrder> materialOrderQueryWrapper = new QueryWrapper<>();
//        materialOrderQueryWrapper.lambda().eq(MaterialOrder::getOrderNo, orderEX.getOrderNo());
//        MaterialOrder materialOrderEX = materialOrderService.getOne(materialOrderQueryWrapper);
//        Long materialOrderId = 0L;
//        if (materialOrderEX != null) {
//            materialOrderId = materialOrderEX.getId();
//        }
//        //插入日志表-异步
//        orderAsync.insertToOrderRecord(orderEX.getId(), orderCourseSnapshotEX.getId(), materialOrderId, WXPayConstants.TO_PAY_FINISH_OPT_REMARK, wxPayVO.getWxReturn());
//        return wxPayVO;
//    }
//
//    /**
//     * 获取开班课程的报名学生id列表
//     *
//     * @param courseClassId 班级课程id
//     * @return 学生id列表
//     */
//    @Override
//    public List<StudentCourseClassVO> getCourseClassOrderStudent(Long courseClassId) {
//        QueryWrapper<OrderCourseSnapshot> courseOrderQueryWrapper = new QueryWrapper<>();
//        courseOrderQueryWrapper.lambda().eq(OrderCourseSnapshot::getCourseClassId, courseClassId);
//        List<OrderCourseSnapshot> list = courseOrderService.list(courseOrderQueryWrapper);
//        List<StudentCourseClassVO> courseStudentList = new ArrayList<>();
//        list.forEach(courseOrder -> {
//            StudentCourseClassVO studentCourseClassVO = new StudentCourseClassVO();
//            studentCourseClassVO.setStudentId(courseOrder.getStudentId());
//            studentCourseClassVO.setStudentName(courseOrder.getStudentName());
//            studentCourseClassVO.setStudentSex(courseOrder.getStudentSex());
//            studentCourseClassVO.setStudentGrade(courseOrder.getStudentGrade());
//            studentCourseClassVO.setStudentClass(courseOrder.getStudentClass());
//            studentCourseClassVO.setGuardianMobile(courseOrder.getGuardianMobile());
//            courseStudentList.add(studentCourseClassVO);
//        });
//        return courseStudentList;
//    }
//
//    /**
//     * 取消订单
//     * 1. 无支付零元订单取消(必定不含教具),订单取消
//     * 2. 有支付的订单取消,有三种情况
//     * 2.1. 课程不含教具,直接全部退款付款金额 materialRefundFlag == 0
//     * 2.2. 课程包含教具，又分成2种情况
//     * 2.2.1. 教具必须购买,直接全部退款金额 materialRefundFlag == 0
//     * 2.2.2. 教具非必须购买
//     * 2.2.2.1. 课程退款,直接全部退款 materialRefundFlag == 0
//     * 2.2.2.2  教具退款,可部分退款教具 materialRefundFlag == 1
//     *
//     * @param orderCancelDTO 取消订单信息
//     * @return 订单id
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public Long cancelPayOrder(OrderCancelDTO orderCancelDTO) {
//        long orderId = orderCancelDTO.getOrderId();
//        Order orderEX = getById(orderCancelDTO.getOrderId());
//        OrderCourseSnapshot orderCourseSnapshotEX = getCourseOrder(orderEX.getOrderNo());
//        checkCancelOrder(orderEX, orderCourseSnapshotEX);
//        Long materialOrderId = 0L;
//        MaterialOrder materialOrderEX = null;
//        if (orderEX.getContainMaterialFlag() == 1) {
//            QueryWrapper<MaterialOrder> materialOrderQueryWrapper = new QueryWrapper<>();
//            materialOrderQueryWrapper.lambda().eq(MaterialOrder::getOrderNo, orderEX.getOrderNo());
//            materialOrderEX = materialOrderService.getOne(materialOrderQueryWrapper);
//            materialOrderId = materialOrderEX.getId();
//        }
//        //无支付零元订单取消(必定不含教具),对应1种情况
//        if (orderEX.getTotalFee() == 0 && orderCancelDTO.getRefundType() == 0) {
//            zeroOrderCancel(orderId, orderCourseSnapshotEX.getId(), orderCourseSnapshotEX.getCourseClassId());
//        }
//        //全部退款情况,对应除2.2.2.2情况
//        if (orderEX.getTotalFee() > 0 && orderCancelDTO.getRefundType() == 0) {
//            allAmountCancel(orderEX, orderCancelDTO, orderCourseSnapshotEX.getId(), materialOrderEX);
//        }
//        //教具退款,可部分退款教具 materialRefundFlag == 1,对应2.2.2.2情况
//        if (orderEX.getTotalFee() > 0 && orderCancelDTO.getRefundType() == 1) {
//            materialOrderCancel(orderEX, orderCancelDTO, materialOrderEX);
//            materialOrderId = materialOrderEX.getId();
//        }
//        //插入日志表-异步
//        String optRemarks = WXPayConstants.CANCEL_ORDER_REMARK;
//        String infoRemarks = orderCancelDTO.getReason();
//        orderAsync.insertToOrderRecord(orderEX.getId(), orderCourseSnapshotEX.getId(), materialOrderId, optRemarks, infoRemarks);
//        return orderId;
//    }
//
//    /**
//     * 订单取消,未支付订单取消
//     *
//     * @param orderId 订单id
//     * @return ""
//     */
//    @Override
//    public Long cancelUnPayOrder(Long orderId) {
//        Order orderEX = getById(orderId);
//        if (orderEX == null) {
//            throw new BusinessException(OrderExceptionEnum.ORDER_NOT_EXIST);
//        }
//        //只有待开班/已付款的订单才能退款
//        if (orderEX.getOrderStatus() != OrderStatusEnum.TO_PAY.getCode()) {
//            throw new BusinessException(OrderExceptionEnum.ORDER_STATUS_ERROR);
//        }
//        Order order = new Order();
//        order.setId(orderId);
//        order.setOrderNo(orderEX.getOrderNo());
//        order.setOrderStatus(OrderStatusEnum.HAVE_CANCEL.getCode());
//        order.setContainMaterialFlag(orderEX.getContainMaterialFlag());
//        String optRemark = "未付款订单取消";
//        updateOrderStatus(order, optRemark, "");
//        return orderId;
//    }
//
//
//    /**
//     * 后台管理系统创建订单
//     *
//     * @param simpleOrderDTO 订单信息
//     * @return orderId
//     * @author xiaol
//     * @since 2020/8/3
//     */
//    @Override
//    public Long createOrderByBack(SimpleOrderDTO simpleOrderDTO) {
//        log.info("用户创建订单数据:{}", simpleOrderDTO);
//        StudentVO studentVO = feignStudentService.getFeignStudentById(simpleOrderDTO.getStudentId());
//        if (studentVO == null || studentVO.getStudentId() == null) {
//            throw new BusinessException(OrderExceptionEnum.FEIGN_ERROR.getCode(), "远程调用用户服务失败");
//        }
//        //同一个学生在同一个班级只能报一次
//        sameClassSignUpValidate(simpleOrderDTO.getClassId(), simpleOrderDTO.getStudentId(), studentVO.getName());
//        AppClassVO appClassVO = redissonLock(simpleOrderDTO.getClassId());
//        //是否是0元课程
//        if (appClassVO.getTotalPrice().compareTo(BigDecimal.ZERO) != 0) {
//            throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), "后台管理系统不能添加非0元课程");
//        }
//        //是否是0元课程
//        if (appClassVO.getClassState() != 1 && appClassVO.getClassState() != 2) {
//            throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), "非待开办状态/已开班状态不能添加学生");
//        }
//        //同一天（同一时间段）只能报一门课程
//        sameTimeOnlyOneClassValidate(simpleOrderDTO.getStudentId(), studentVO.getName(), appClassVO.getCourseName(), appClassVO.getCourseWeek(), appClassVO.getClassTime());
//        //报名只能报对应适用年级的课程
//        courseGradeValidate(String.valueOf(studentVO.getGradeYear()), appClassVO.getCourseGrade(), appClassVO.getCourseGradeName());
//        String orderNo = generateOrderNo();
//        Order order = new Order();
//        //主订单信息
//        order.setOrderNo(orderNo);
//        order.setCourseClassId(simpleOrderDTO.getClassId());
//        order.setCreateId(UserUtil.getLoginUserId());
//        // 班级状态：0待报名 1报名中 2已开班 3取消报名 4已完成 5过期
//        order.setOrderStatus(appClassVO.getClassStatus());
//        //付款渠道是 后台添加
//        order.setPayChannel(2);
//        if (!save(order)) {
//            log.error("后台管理系统创建订单有误:{}", order);
//            throw new BusinessException(OrderExceptionEnum.CREATE_ORDER_ERROR);
//        }
//        //插入课程订单表
//        OrderCourseSnapshot orderCourseSnapshot = new OrderCourseSnapshot();
//        orderCourseSnapshot.setCourseCreateId(appClassVO.getCourseCreateId());
//        orderCourseSnapshot.setOrderNo(orderNo);
//        orderCourseSnapshot.setMainOrderId(order.getId());
//        fillCourseOrder(appClassVO, studentVO, orderCourseSnapshot);
//        orderCourseSnapshot.setOrderStatus(order.getOrderStatus());
//        courseOrderService.save(orderCourseSnapshot);
//        //插入日志表-异步
//        orderAsync.insertToOrderRecord(order.getId(), orderCourseSnapshot.getId(), 0L, WXPayConstants.CREATE_ORDER_BACK, WXPayConstants.CREATE_ORDER_BACK);
//        // 如果课程已经开班插入 学生课表
//        if (ClassAuditEnum.BEGIN_CLASS.getCode() == appClassVO.getClassState()) {
//            StudentCourseClassVO studentCourseClassVO = new StudentCourseClassVO();
//            studentCourseClassVO.setGuardianMobile(orderCourseSnapshot.getGuardianMobile());
//            studentCourseClassVO.setStudentId(simpleOrderDTO.getStudentId());
//            studentCourseClassVO.setStudentName(orderCourseSnapshot.getStudentName());
//            studentCourseClassVO.setStudentSex(orderCourseSnapshot.getStudentSex());
//            studentCourseClassVO.setStudentGrade(orderCourseSnapshot.getStudentGrade());
//            studentCourseClassVO.setStudentClass(orderCourseSnapshot.getStudentClass());
//            feignClassService.saveStudentCourseSchedule(simpleOrderDTO.getClassId(), studentCourseClassVO);
//        }
//        return order.getId();
//    }
//
//
//    private OrderCourseSnapshot getCourseOrder(String orderNo) {
//        QueryWrapper<OrderCourseSnapshot> courseOrderQueryWrapper = new QueryWrapper<>();
//        courseOrderQueryWrapper.lambda().eq(OrderCourseSnapshot::getOrderNo, orderNo);
//        OrderCourseSnapshot orderCourseSnapshotEX = courseOrderService.getOne(courseOrderQueryWrapper);
//        if (orderCourseSnapshotEX == null) {
//            throw new BusinessException(OrderExceptionEnum.COURSE_ORDER_NOT_EXIST);
//        }
//        return orderCourseSnapshotEX;
//    }
//
//    /**
//     * 验证金额
//     *
//     * @param appClassVO 课程兴趣
//     * @param orderDTO   订单表单
//     */
//    private void checkMoney(AppClassVO appClassVO, OrderDTO orderDTO) {
//        //金额为负数验证
//        if (orderDTO.getTotalPrice().compareTo(BigDecimal.ZERO) < 0
//                || orderDTO.getCoursePrice().compareTo(BigDecimal.ZERO) < 0
//                || orderDTO.getMaterialPrice().intValue() < 0) {
//            log.error("提交课程:{}金额为负数", orderDTO.getCourseClassId());
//            throw new BusinessException(OrderExceptionEnum.COURSE_AMOUNT_ERROR);
//        }
//
//        BigDecimal coursePrice = orderDTO.getCoursePrice();
//        BigDecimal totalPrice = orderDTO.getTotalPrice();
//        BigDecimal classCoursePrice = appClassVO.getCourseTotalPrice();
//        //没有教具价格
//        if (orderDTO.getContainMaterialFlag() == 0) {
//            //不相等说明金额有误,订单总金额!=课程金额 || 班级课程总金额!=课程金额
//            if (totalPrice.compareTo(coursePrice) != 0 || classCoursePrice.compareTo(coursePrice) != 0) {
//                log.error("不含教具===学生Id:{},学生姓名:{},班级Id:{}总金额:{}!=课程金额:{} || 班级课程总金额:{}!=课程金额:{}",
//                        orderDTO.getStudentId(), orderDTO.getStudentName(), orderDTO.getCourseClassId(), totalPrice, coursePrice, classCoursePrice, coursePrice);
//                throw new BusinessException(OrderExceptionEnum.COURSE_AMOUNT_ERROR);
//            }
//        }
//        //有教具价格
//        if (orderDTO.getContainMaterialFlag() == 1) {
//            //订单教具金额
//            BigDecimal materialPrice = orderDTO.getMaterialPrice();
//            BigDecimal total = BigDecimalUtil.plus(coursePrice, materialPrice);
//            //班级课程教具金额
//            BigDecimal courseMaterialPrice = appClassVO.getCourseMaterialPrice();
//            BigDecimal courseTotalPrice = BigDecimalUtil.plus(classCoursePrice, courseMaterialPrice);
//            //不相等说明金额有误,表单中订单总额=表单教具金额+表单课程金额  || 表单中订单总额=班级课程总额
//            if (totalPrice.compareTo(total) != 0 || totalPrice.compareTo(courseTotalPrice) != 0) {
//                log.error("包含教具===学生Id:{},学生姓名:{},课程Id:{},表单中订单总额:{}=表单教具金额+表单课程金额(total:{})  || 表单中订单总额:{}=班级课程总额:{}",
//                        orderDTO.getStudentId(), orderDTO.getStudentName(), orderDTO.getCourseClassId(), totalPrice, total, totalPrice, courseTotalPrice);
//                throw new BusinessException(OrderExceptionEnum.COURSE_AMOUNT_ERROR);
//            }
//        }
//    }
//
//
//    /**
//     * 主订单信息
//     *
//     * @param orderDTO 订单表单
//     * @param order    订单实体
//     * @param orderNo  变化
//     */
//    private void fillMainOrder(OrderDTO orderDTO, Order order, String orderNo) {
//        order.setId(IdGenerator.getId());
//        order.setOrderNo(orderNo);
//        order.setCourseClassId(orderDTO.getCourseClassId());
//        order.setCreateId(UserUtil.getLoginUserId());
//        order.setCourseOrderFee(BigDecimalUtil.getMoneyFee(orderDTO.getCoursePrice()));
//        Integer totalFee = BigDecimalUtil.getMoneyFee(orderDTO.getTotalPrice());
//        if (totalFee == 0) {
//            order.setOrderStatus(OrderStatusEnum.TO_OPEN_CLASS.getCode());
//        } else {
//            order.setOrderStatus(OrderStatusEnum.TO_PAY.getCode());
//        }
//        order.setTotalFee(totalFee);
//        order.setContainMaterialFlag(orderDTO.getContainMaterialFlag());
//
//    }
//
//
//    /**
//     * 课程订单信息
//     *
//     * @param appClassVO  班级课程信息
//     * @param studentVO   学生信息
//     * @param orderCourseSnapshot 课程订单实体
//     */
//    private void fillCourseOrder(AppClassVO appClassVO, StudentVO studentVO, OrderCourseSnapshot orderCourseSnapshot) {
//        //班级课程信息
//        orderCourseSnapshot.setCourseId(appClassVO.getCourseId());
//        orderCourseSnapshot.setCourseClassId(appClassVO.getClassId());
//        orderCourseSnapshot.setCourseClassName(appClassVO.getClassName());
//        Integer courseHourFee = BigDecimalUtil.getMoneyFee(appClassVO.getCourseHourPrice());
//        orderCourseSnapshot.setCourseHourFee(courseHourFee);
//        Integer courseTotalFee = BigDecimalUtil.getMoneyFee(appClassVO.getCourseTotalPrice());
//        orderCourseSnapshot.setCourseTotalFee(courseTotalFee);
//        orderCourseSnapshot.setCourseHourCount(appClassVO.getCourseHourCount());
//        orderCourseSnapshot.setCourseName(appClassVO.getCourseName());
//        orderCourseSnapshot.setCourseTime(appClassVO.getCourseTime());
//        orderCourseSnapshot.setCourseWeek(appClassVO.getCourseWeek());
//        orderCourseSnapshot.setClassTime(appClassVO.getClassTime());
//        orderCourseSnapshot.setClassOpenDate(appClassVO.getClassOpenDate());
//        orderCourseSnapshot.setTeacherName(appClassVO.getTeacherName());
//        orderCourseSnapshot.setClassRoomName(appClassVO.getClassRoomName());
//        orderCourseSnapshot.setCourseCreateName(appClassVO.getCourseCreateName());
//        if (appClassVO.getOrganId() == null || appClassVO.getOrganId() == 0L) {
//            //设置成学校
//            orderCourseSnapshot.setCourseCreateType(1);
//        }
//        //学生信息
//        orderCourseSnapshot.setStudentId(studentVO.getStudentId());
//        orderCourseSnapshot.setStudentName(studentVO.getName());
//        orderCourseSnapshot.setStudentSex(studentVO.getSex());
//        orderCourseSnapshot.setStudentBirthday(studentVO.getBirthday());
//        orderCourseSnapshot.setSchoolId(studentVO.getSchoolId());
//        orderCourseSnapshot.setSchoolName(studentVO.getSchoolName());
////        OrderCourseSnapshot.setStudentClassId(appClassVO.getClassId());
//        orderCourseSnapshot.setStudentGrade(GradeEnum.getName(studentVO.getGradeYear()));
//        orderCourseSnapshot.setStudentClass(studentVO.getGradeClass());
//        orderCourseSnapshot.setGuardianMobile(studentVO.getGuardianMobile());
//    }
//
//
//    private void accept(OrderAppPageVO orderAppPageVO) {
//        //课程金额
//        orderAppPageVO.setCourseOrderPrice(BigDecimalUtil.getMoneyBigDecimal(orderAppPageVO.getCourseOrderPrice()));
//        orderAppPageVO.setTotalPrice(BigDecimalUtil.getMoneyBigDecimal(orderAppPageVO.getTotalPrice()));
//        if (orderAppPageVO.getContainMaterialFlag() == 1) {
//            orderAppPageVO.setMaterialOrderPrice(BigDecimalUtil.getMoneyBigDecimal(orderAppPageVO.getMaterialOrderPrice()));
//        } else {
//            orderAppPageVO.setMaterialOrderPrice(null);
//        }
//        orderAppPageVO.setOrderStatusName(OrderStatusEnum.getName(orderAppPageVO.getOrderStatus()));
//    }
//
//    /**
//     * 同一个学生在同一个班级只能报一次
//     *
//     * @param courseClassId 班级
//     * @param studentId     学生id
//     * @param studentName   学生姓名
//     */
//    private void sameClassSignUpValidate(Long courseClassId, Long studentId, String studentName) {
//        QueryWrapper<OrderCourseSnapshot> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(OrderCourseSnapshot::getCourseClassId, courseClassId)
//                .eq(OrderCourseSnapshot::getStudentId, studentId)
//                .in(OrderCourseSnapshot::getOrderStatus, 0, 1, 2);
//        OrderCourseSnapshot orderCourseSnapshotEX = courseOrderService.getOne(queryWrapper);
//        queryWrapper = null;//help gc
//        if (orderCourseSnapshotEX != null) {
//            //有待支付的订单
//            StringBuilder sb = new StringBuilder();
//            sb.append("该课程 ").append(studentName);
//            if (orderCourseSnapshotEX.getOrderStatus() == 0) {
//                sb.append(" 有待支付的订单,请到我的订单列表进行支付!");
//                throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), sb.toString());
//            }
//            if (orderCourseSnapshotEX.getOrderStatus() == 1 || orderCourseSnapshotEX.getOrderStatus() == 2) {
//                sb.append(" 已报名,无需重复报名!");
//                throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), sb.toString());
//            }
//        }
//    }
//
//    /**
//     * 同一天（同一时间段）只能报一门课程
//     *
//     * @param studentId   学生id
//     * @param studentName 学生姓名
//     */
//    private void sameTimeOnlyOneClassValidate(Long studentId, String studentName, String courseName, String courseWeek, String classTime) {
//        //同一个学生同一时间只能报名一个课程
//        QueryWrapper<OrderCourseSnapshot> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(OrderCourseSnapshot::getStudentId, studentId)
//                .in(OrderCourseSnapshot::getOrderStatus, 1, 2);
//        List<OrderCourseSnapshot> orderCourseSnapshotList = courseOrderService.list(queryWrapper);
//        queryWrapper = null;//help gc
//        if (CollUtil.isNotEmpty(orderCourseSnapshotList)) {
//            String[] currentClassWeekArr = courseWeek.split(",");
//            String[] currentClassTimeArr = classTime.split("~");
//            //当前报名的课程时间段
//            LocalTime currentClassTimeStart = LocalTime.parse(currentClassTimeArr[0]);
//            LocalTime currentClassTimeEnd = LocalTime.parse(currentClassTimeArr[1]);
//            orderCourseSnapshotList.forEach(courseOrder -> {
//                String[] weekArr = courseOrder.getCourseWeek().split(",");
//                Set<String> sameDaySet = ArrayUtil.getSame(currentClassWeekArr, weekArr);
//                //如果有相同的，则进行时间段比较,假设已经报名课程的时间段是 3:00~4:00,报名课程的时间点开始时间或者结束时间在这范围内则返回错误信息
//                if (CollUtil.isNotEmpty(sameDaySet)) {
////                    String weekStr = getIntWeekToString(sameDaySet);
//                    String[] timeArr = courseOrder.getClassTime().split("~");
//                    //已经报名课程的时间段
//                    LocalTime classTimeStart = LocalTime.parse(timeArr[0]);
//                    LocalTime classTimeEnd = LocalTime.parse(timeArr[1]);
//                    //时间段相同
//                    if (currentClassTimeStart.equals(classTimeStart) || currentClassTimeEnd.equals(classTimeEnd)) {
//                        StringBuilder sb = new StringBuilder();
//                        sb.append(studentName).append("已报名 ")
//                                .append(courseOrder.getCourseName())
//                                .append(" 报名失败");
//                        throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), sb.toString());
//                    }
//
//                    //已参加课程的时间段与当前课程比较
//                    if ((classTimeStart.isBefore(currentClassTimeStart) && classTimeEnd.isAfter(currentClassTimeStart))
//                            || (classTimeStart.isBefore(currentClassTimeEnd) && classTimeEnd.isAfter(currentClassTimeEnd))) {
//                        StringBuilder sb = new StringBuilder();
//                        sb.append(studentName).append("已报名 ")
//                                .append(courseOrder.getCourseName())
//                                .append(" 报名失败");
//                        throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), sb.toString());
//                    }
//                    //当前课程的时间段与已参加课程比较
//                    if ((currentClassTimeStart.isBefore(classTimeStart) && currentClassTimeEnd.isAfter(classTimeStart))
//                            || (currentClassTimeStart.isBefore(classTimeEnd) && currentClassTimeEnd.isAfter(classTimeEnd))) {
//                        StringBuilder sb = new StringBuilder();
//                        sb.append(studentName).append("已报名 ")
//                                .append(courseOrder.getCourseName())
//                                .append(" 报名失败");
//                        throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), sb.toString());
//                    }
//
//                }
//            });
//
//        }
//    }
//
//    private String getIntWeekToString(Set<String> weekSet) {
//        StringBuilder courseTime = new StringBuilder();
//        for (String courseWeekStr : weekSet) {
//            courseTime.append("周").append(getWeekStr(Integer.valueOf(courseWeekStr))).append("、");
//        }
//        courseTime.deleteCharAt(courseTime.length() - 1);
//        return courseTime.toString();
//    }
//
//    private String getWeekStr(Integer val) {
//        switch (val) {
//            case 1:
//                return "一";
//            case 2:
//                return "二";
//            case 3:
//                return "三";
//            case 4:
//                return "四";
//            case 5:
//                return "五";
//            case 6:
//                return "六";
//            case 7:
//                return "日";
//            default:
//                return "";
//        }
//    }
//
//    /**
//     * 费用不超过150的限制，平均每月，每个学期按4个月算
//     *
//     * @param studentId   学生
//     * @param coursePrice 课程价格
//     * @param studentName 学生姓名
//     */
//    private void registrationFeeValidate(Long studentId, BigDecimal coursePrice, String studentName) {
//        //江西上饶教育局对每个学生每个月金额不能超过150限制 9月1日 正式上课; 2021年1月29日 开始放寒假。本学期共计21.5周。
//        QueryWrapper<OrderCourseSnapshot> queryWrapper = new QueryWrapper<>();
//        LocalDate semesterStart = LocalDate.of(2020, 9, 1);
//        LocalDate semesterEnd = LocalDate.of(2021, 1, 29);
//        queryWrapper.lambda().eq(OrderCourseSnapshot::getStudentId, studentId)
//                .in(OrderCourseSnapshot::getOrderStatus, 1, 2)
//                .between(OrderCourseSnapshot::getCreateTime, semesterStart, semesterEnd);
//        List<OrderCourseSnapshot> list = courseOrderService.list(queryWrapper);
//        queryWrapper = null;//help gc
//        Integer totalMoneyFee = 0;
//        for (OrderCourseSnapshot orderCourseSnapshot : list) {
//            totalMoneyFee += orderCourseSnapshot.getCourseTotalFee();
//        }
//        BigDecimal moneyBigDecimal = BigDecimalUtil.plus(coursePrice, BigDecimalUtil.getMoneyBigDecimal(totalMoneyFee));
//        if (moneyBigDecimal != null) {
//            int months = Period.between(semesterStart, semesterEnd).getMonths() + 1;
//            BigDecimal avgAmount = BigDecimalUtil.div(moneyBigDecimal.toString(), String.valueOf(months));
//            if (avgAmount.intValue() > 150) {
//                throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), studentName + "报名课程金额已达到教育局收费标准");
//            }
//        }
//    }
//
//    /**
//     * 报名只能报对应适用年级的课程
//     *
//     * @param studentGrade    学生年级
//     * @param courseGrade     课程适用年级
//     * @param courseGradeName 课程适用年级中文
//     */
//    private void courseGradeValidate(String studentGrade, String courseGrade, String courseGradeName) {
//        boolean flag = false;
//        String[] courseGradeArr = courseGrade.split(",");
//        for (String gradeStr : courseGradeArr) {
//            if (studentGrade.equals(gradeStr)) {
//                flag = true;
//            }
//        }
//        if (!flag) {
//            throw new BusinessException(OrderExceptionEnum.STUDENT_ORDER_ERROR.getCode(), "该课程仅适用于" + courseGradeName);
//        }
//    }
//
//    /**
//     * 生成流水号
//     *
//     * @return
//     */
//    private String generateOrderNo() {
//        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
//        return "SO" + snowflake.nextIdStr();
//    }
//
//
//
//
//    /**
//     * 退款订单验证
//     *
//     * @param orderEX 订单
//     */
//    private void checkCancelOrder(Order orderEX, OrderCourseSnapshot orderCourseSnapshotEX) {
//        if (orderEX == null) {
//            throw new BusinessException(OrderExceptionEnum.ORDER_NOT_EXIST);
//        }
//        if (orderCourseSnapshotEX == null) {
//            throw new BusinessException(OrderExceptionEnum.COURSE_ORDER_NOT_EXIST);
//        }
//        //只有待开班/已付款的订单才能退款
//        if (orderEX.getOrderStatus() != OrderStatusEnum.TO_OPEN_CLASS.getCode()) {
//            throw new BusinessException(OrderExceptionEnum.ORDER_STATUS_ERROR);
//        }
//    }
//
//
//    /**
//     * 零元订单取消
//     *
//     * @param orderId       订单id
//     * @param courseOrderId 课程订单id
//     * @param courseClassId 课程班级id
//     */
//    private void zeroOrderCancel(Long orderId, Long courseOrderId, Long courseClassId) {
//        int orderStatus = OrderStatusEnum.HAVE_CANCEL.getCode();
//        Order order = new Order();
//        order.setId(orderId);
//        order.setOrderStatus(orderStatus);
//        updateById(order);
//        //修改课程订单状态
//        OrderCourseSnapshot orderCourseSnapshot = new OrderCourseSnapshot();
//        orderCourseSnapshot.setOrderStatus(orderStatus);
//        orderCourseSnapshot.setId(courseOrderId);
//        courseOrderService.updateById(orderCourseSnapshot);
//        //远程调用
//        feignClassService.cancelSignUpNumber(courseClassId);
//    }
//
//    /**
//     * 全额退款
//     *
//     * @param orderEX         订单信息
//     * @param orderCancelDTO  退款信息
//     * @param courseOrderId   课程订单id
//     * @param materialOrderEX 教具订单id
//     * @return
//     */
//    private void allAmountCancel(Order orderEX, OrderCancelDTO orderCancelDTO, Long courseOrderId, MaterialOrder materialOrderEX) {
//        int orderStatus = OrderStatusEnum.TO_REFUND.getCode();
//        Order order = new Order();
//        order.setId(orderEX.getId());
//        order.setOrderStatus(orderStatus);
//        updateById(order);
//        //修改课程订单状态
//        OrderCourseSnapshot orderCourseSnapshot = new OrderCourseSnapshot();
//        orderCourseSnapshot.setOrderStatus(orderStatus);
//        orderCourseSnapshot.setId(courseOrderId);
//        courseOrderService.updateById(orderCourseSnapshot);
//        if (materialOrderEX != null) {
//            MaterialOrder materialOrder = new MaterialOrder();
//            materialOrder.setOrderStatus(orderStatus);
//            materialOrder.setId(materialOrderEX.getId());
//            materialOrderService.updateById(materialOrder);
//        }
//        refundService.refundOrder(orderEX, orderCancelDTO);
//    }
//
//    /**
//     * 教具订单退款
//     *
//     * @param orderEX         订单信息
//     * @param orderCancelDTO  退款信息
//     * @param materialOrderEX 教具订单id
//     */
//    private void materialOrderCancel(Order orderEX, OrderCancelDTO orderCancelDTO, MaterialOrder materialOrderEX) {
//        if (materialOrderEX != null) {
//            throw new BusinessException(OrderExceptionEnum.MATERIAL_ORDER_NOT_EXIST);
//        }
//        Integer orderStatus = OrderStatusEnum.MATERIAL_TO_REFUND.getCode();
//        Order order = new Order();
//        order.setId(orderEX.getId());
//        order.setOrderStatus(orderStatus);
//        updateById(order);
//        //教具
//        MaterialOrder materialOrder = new MaterialOrder();
//        materialOrder.setOrderStatus(orderStatus);
//        materialOrder.setId(materialOrderEX.getId());
//        materialOrderService.updateById(materialOrder);
//        refundService.refundOrder(orderEX, orderCancelDTO);
//    }
//}
